﻿//新增采集规则设置
InsertExtend_CollectSetInfo = function() {


    var channelsTree = Ext.create("Ext.ux.comboboxtree", {
        name: 'ChannelId',
        storeUrl: '/Manager/Module_Manager/List/m',
        fieldLabel: "<font color='red'>*</font>所属栏目",
        labelAlign: 'right',
        treeNodeParameter: 'text',
        displayField: 'text',
        queryMode: 'local',
        valueField: 'id'
    });
    var InsertExtend_CollectSetInfoForm = Ext.create("Ext.form.Panel", {
        width: 800,
        height: 530,
        plain: true,
        autoScroll: true,
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 120,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [
        {
            xtype: 'tabpanel',
            plain: true,
            activeTab: 0,
            labelWidth: 120,
            height:530,
            bodyStyle: "padding:15px 0 0 0",
            items: [{
                title: '采集列表设置',
                defaults: { labelWidth: 120, labelAlign: 'right', msgTarget: "side" },
                defaultType: 'textfield',
                items: [
                   {
                       name: "Name",
                       fieldLabel: "<font color='red'>*</font>采集标题",
                       allowBlank: false,
                       blankText: "采集标题号不能为空"
                   }, {
                       xtype: 'fieldcontainer',
                       fieldLabel: "<font color='red'>*</font>采集列表地址",
                       labelWidth: 120,
                       layout: 'table',
                       labelAlign: 'right',
                       defaults: {
                           flex: 1,
                           hideLabel: true
                       },
                       items: [
                            {
                                xtype: 'textfield',
                                name: "Url",
                                width: 300,
                                fieldLabel: "<font color='red'>*</font>采集列表地址",
                                allowBlank: false
                            },
                            { xtype: 'displayfield', value: 'url参考：http://www.baidu.com/page?pageIndex={*}' }
                        ]
                     }, {
                            xtype: 'fieldcontainer',
                            fieldLabel: "采集列表第一页地址",
                            labelWidth: 120,
                            layout: 'table',
                            labelAlign: 'right',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [
                            {
                                xtype: 'textfield',
                                name: "FirstUrl",
                                width: 300,
                                fieldLabel: "采集列表第一页地址",
                                allowBlank: true
                            },
                            { xtype: 'displayfield', value: 'url参考：http://www.baidu.com/page?pageIndex=1' }
                        ]


                   }, {
                       xtype: 'fieldcontainer',
                       fieldLabel: "采集列表",
                       labelWidth: 120,
                       layout: 'table',
                       labelAlign: 'right',
                       defaults: {
                           flex: 1,
                           hideLabel: true
                       },
                       items: [
                            { xtype: 'displayfield', value: '包含' },
                            {
                                xtype: 'textfield',
                                name: 'IncludeStr',
                                margin: '0 5 0 0',
                                flex: 1,
                                allowBlank: false
                            },
                            { xtype: 'displayfield', value: '不包含' },
                            {
                                xtype: 'textfield',
                                name: 'WithoutStr',
                                flex: 1
                            },
                            { xtype: 'displayfield', value: 'Url匹配正则' },
                            {
                                xtype: 'textfield',
                                name: 'UrlRegex',
                                flex: 1
                            }
                        ]

                   },{
                    xtype: 'fieldcontainer',
                    fieldLabel: "<font color='red'>*</font>采集内容",
                    labelWidth: 110,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: '起始标记' },
                            {
                                xtype: 'textfield',
                                name: 'ListMatchLeft',
                                flex: 1,
                                allowBlank: true
                            },
                            { xtype: 'displayfield', value: '终止标记' },
                            {
                                xtype: 'textfield',
                                name: 'ListMatchRight',
                                flex: 1,
                                allowBlank: true
                            }
                        ]
                }, {
                       xtype: 'fieldcontainer',
                       fieldLabel: "<font color='red'>*</font>列表地址变化范围",
                       labelWidth: 100,
                       layout: 'table',
                       labelAlign: 'right',
                       defaults: {
                           flex: 1,
                           hideLabel: true
                       },
                       items: [
                            { xtype: 'displayfield', value: '起始' },
                            {
                                xtype: 'numberfield',
                                name: 'StartNum',
                                width: 40,
                                flex: 1,
                                allowBlank: false
                            },
                            { xtype: 'displayfield', value: '终止' },
                            {
                                xtype: 'numberfield',
                                name: 'EndNum',
                                flex: 1,
                                width: 40,
                                allowBlank: false
                            },
                            { xtype: 'displayfield', value: '递增' },
                            {
                                xtype: 'numberfield',
                                name: 'AddNum',
                                flex: 1,
                                width: 40,
                                allowBlank: false
                            },
                        ]
                        }, {
                            xtype: 'fieldcontainer',
                            fieldLabel: "<font color='red'>*</font>列表页面编码",
                            labelWidth: 100,
                            layout: 'table',
                            labelAlign: 'right',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [
                           {
                               name: "Encoding",
                               xtype: "combo",
                               //传入后台真实值value field /value
                               editable: false,
                               value: "utf-8",
                               store: Ext.create('Ext.data.Store', {
                                   fields: ['show', 'value'],
                                   data: [
			                    { "show": "gb2312", "value": "gb2312" },
			                    { "show": "utf-8", "value": "utf-8" }
			                ]
                               }),
                               queryMode: 'local',
                               displayField: 'show',
                               valueField: 'value'
                           }, { xtype: 'displayfield', value: '内容页编码' }, {
                               name: "ContentEncoding",
                               xtype: "combo",
                               //传入后台真实值value field /value
                               editable: false,
                               value: "",
                               store: Ext.create('Ext.data.Store', {
                                   fields: ['show', 'value'],
                                   data: [
                                    { "show": "列表页编码", "value": "" },
			                    { "show": "gb2312", "value": "gb2312" },
			                    { "show": "utf-8", "value": "utf-8" }
			                ]
                               }),
                               queryMode: 'local',
                               displayField: 'show',
                               valueField: 'value'
                           }
                        ]
                        }, channelsTree, {
                       xtype: 'fieldcontainer',
                       fieldLabel: "是否启用",
                       labelWidth: 100,
                       layout: 'table',
                       labelAlign: 'right',
                       defaults: {
                           flex: 1,
                           hideLabel: true
                       },
                       items: [
                           
                            {
                                name: "Enabled",
                                fieldLabel: "是否启用",
                                xtype: "combo",
                                //传入后台真实值value field /value
                                xtype: 'combo',
                                editable: false,
                                anchor: '90%',
                                value: true,
                                store: Ext.create('Ext.data.Store', {
                                    fields: ['show', 'value'],
                                    data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
                                }),
                                queryMode: 'local',
                                displayField: 'show',
                                valueField: 'value'
                            },
                            { xtype: 'displayfield', value: '是否自动更新' },
                            {
                                name: "IsAutoUpdate",
                                xtype: "combo",
                                //传入后台真实值value field /value
                                xtype: 'combo',
                                editable: false,
                                anchor: '90%',
                                value: true,
                                store: Ext.create('Ext.data.Store', {
                                    fields: ['show', 'value'],
                                    data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
                                }),
                                queryMode: 'local',
                                displayField: 'show',
                                valueField: 'value'
                            }
                        ]
                   }, {
                       name: "Cookie",
                       fieldLabel: "Cookie"
                   }, {
                       xtype: 'numberfield',
                       name: "orderNum",
                       value: 0,
                       fieldLabel: "优先级(越大越优先)",
                       allowBlank: false
                   }, {
                       name: "ThreadInterval",
                       xtype: "numberfield",
                       value: 360,
                       fieldLabel: "<font color='red'>*</font>采集内容间隔时间(秒)",
                       allowBlank: false
                   }, {
                       name: "DoTime",
                       xtype: "numberfield",
                       value: 360,
                       fieldLabel: "<font color='red'>*</font>采集循环时间(分)",
                       allowBlank: false
}]



            }, {
                title: '采集内容设置',
                defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
                defaultType: 'textfield',
                items: [
                {
                    xtype: 'fieldcontainer',
                    fieldLabel: "采集标题",
                    labelWidth: 110,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: '起始标记' },
                            {
                                xtype: 'textfield',
                                name: 'TitleMatchLeft',
                                flex: 1
                            },
                            { xtype: 'displayfield', value: '终止标记' },
                            {
                                xtype: 'textfield',
                                name: 'TitleMatchRight',
                                flex: 1
                            }
                        ]
                }, {
                    xtype: 'fieldcontainer',
                    fieldLabel: "<font color='red'>*</font>采集内容",
                    labelWidth: 110,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: '起始标记' },
                            {
                                xtype: 'textfield',
                                name: 'ContentMatchLeft',
                                flex: 1,
                                allowBlank: false
                            },
                            { xtype: 'displayfield', value: '终止标记' },
                            {
                                xtype: 'textfield',
                                name: 'ContentMatchRight',
                                flex: 1,
                                allowBlank: false
                            }
                        ]
                }, {
                    xtype: 'fieldcontainer',
                    fieldLabel: '替换规则',
                    labelWidth: 100,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: '标题' },
                            {
                                xtype: 'textareafield',
                                name: 'TitleReplaceStr',
                                width: 220,
                                flex: 1
                            },
                            { xtype: 'displayfield', value: '内容' },
                            {
                                xtype: 'textareafield',
                                name: 'ContentReplaseStr',
                                width: 220,
                                flex: 1
                            },
                            { xtype: 'displayfield', value: 'oldStr=blank，blank代表替换为空可以替换为你想要替换的字符串,如oldStr=abc,多个以(/n换行)间隔 ' }
                        ]
                   }, {
                       name: "FormatStr",
                       xtype: 'textareafield',
                       fieldLabel: "组装内容"
                   }, {
                       xtype: 'fieldcontainer',
                       fieldLabel: "<font color='red'>*</font>采集内容",
                       labelWidth: 110,
                       layout: 'table',
                       labelAlign: 'right',
                       defaults: {
                           flex: 1,
                           hideLabel: true
                       },
                       items: [
                            { xtype: 'displayfield', value: '第二页正则地址' },
                            {
                                xtype: 'textfield',
                                name: 'SecondUrlRegex',
                                flex: 1
                            },
                            { xtype: 'displayfield', value: '第二内容页正则' },
                            {
                                xtype: 'textfield',
                                name: 'SecondContentRegex',
                                flex: 1
                            },
                            { xtype: 'displayfield', value: '（如果没有填写第二页地址，则第二内容正则）' }
                        ]
                   }, {
                    xtype: 'fieldcontainer',
                    fieldLabel: '采集内容截取',
                    labelWidth: 100,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: '左边' },
                            {
                                xtype: 'numberfield',
                                name: 'ContentRemoveLeftLength',
                                width: 40,
                                flex: 1
                            },
                            { xtype: 'displayfield', value: '右边' },
                            {
                                xtype: 'numberfield',
                                name: 'ContentRemoveRightLength',
                                flex: 1,
                                width: 40
                            }
                        ]
                }, {
                    name: "PagingReg",
                    fieldLabel: "分页规则"
                }, {
                    xtype: 'checkboxgroup',
                    fieldLabel: '采集内容设置',
                    name: "checkboxgroup2",
                    // Arrange checkboxes into two columns, distributed vertically
                    columns: 3,
                    width: 600,
                    defaults: {
                        lableWidth: 150
                    },
                    items: [
                              { boxLabel: '是否包含Html', width: 180, name: 'IsIncludeHtml', inputValue: '1', checked: true },
                            { boxLabel: '是否自动获取描述', width: 180, name: 'IsAutoDescription', inputValue: '1' },
                            { boxLabel: '是否自动获取关键词', width: 180, name: 'IsAutoKeyWord', inputValue: '1' },
                            { boxLabel: '是否包含超链接', width: 180, name: 'IsIncludeLink', inputValue: '1' },
                            { boxLabel: '是否分页', width: 180, name: 'IsPaging', inputValue: '1' },
                            { boxLabel: '是否包含Script', width: 180, name: 'IsIncludeScript', inputValue: '1' },
                            { boxLabel: '是否包含class样式', width: 180, name: 'IsIncludeClass', inputValue: '1' },
                            { boxLabel: '是否包换Style', width: 180, name: 'IsIncludeStyle', inputValue: '1' },
                            { boxLabel: '是否包含任何连接', width: 180, name: 'IsIncludeColor', inputValue: '0', checked: false },
                            { boxLabel: '是否包含图片', width: 180, name: 'IsIncludeImg', inputValue: '1' },
                              { boxLabel: '是否自动提取缩略图', width: 180, name: 'IsAutoImg', inputValue: '1' },
                               { boxLabel: '是否推荐', width: 180, name: 'IsRecommend', inputValue: '1' },
                            { boxLabel: '是否包含框架', width: 180, name: 'IsIncludeFrame', inputValue: '1' }

                        ]
                }

                         ]
            }, {
                title: '采集列表测试',
                defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
                defaultType: 'textfield',
                items: [{
                    xtype: 'fieldcontainer',
                    fieldLabel: "<font color='red'>*</font>测试采集列表",
                    labelWidth: 110,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: 'Url' },
                           
                                Ext.create('Ext.Button', {
                                    text: '测试采集列表',
                                    handler: function() {
                                        //alert(InsertExtend_CollectSetInfoForm.getForm().isValid())
                                        if (InsertExtend_CollectSetInfoForm.getForm().isValid()) {
                                            //弹出效果 Ext.MessageBox.alert("asdf");
                                            Ext.MessageBox.show
                                                    (
                                                        {
                                                            msg: '正在保存，请稍等...',
                                                            progressText: 'Saving...',
                                                            width: 300,
                                                            wait: true,
                                                            waitConfig: { interval: 200 },
                                                            icon: 'download',
                                                            animEl: 'saving'
                                                        }
                                                    );
                                                        setTimeout(function () { }, 1000);
                                                        
                                            InsertExtend_CollectSetInfoForm.form.submit({
                                                url: "/manager/Extend_CollectSetInfo/CollectList/",
                                                method: "POST",
                                                success: function(form, action) {
                                                    Ext.MessageBox.hide();
                                                    //成功后
                                                    InsertExtend_CollectSetInfoForm.getForm().findField("reListContent").setValue(action.result.message);
                                                },
                                                failure: function(form, action) {
                                                    Ext.MessageBox.alert("提示!", "新增失败!");
                                                }
                                            });
                                        }
                                    }
                                })
                        ]
                }, {
                    xtype: 'textareafield',
                    name: 'reListContent',
                    fieldLabel: "采集内容",
                    width: 500,
                    height: 300,
                    flex: 1
                }

                         ]
            }, {
                title: '采集列表内容',
                defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
                defaultType: 'textfield',
                items: [{
                    xtype: 'fieldcontainer',
                    fieldLabel: "<font color='red'>*</font>测试采集内容",
                    labelWidth: 110,
                    layout: 'table',
                    labelAlign: 'right',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    },
                    items: [
                            { xtype: 'displayfield', value: 'Url' },
                            {
                                xtype: 'textfield',
                                name: 'Urlcontent',
                                width: 360,
                                flex: 1
                            },
                                Ext.create('Ext.Button', {
                                    text: '测试采集内容',
                                    handler: function() {
                                        //alert(InsertExtend_CollectSetInfoForm.getForm().isValid())
                                        if (InsertExtend_CollectSetInfoForm.getForm().isValid()) {
                                          
                                            //弹出效果 Ext.MessageBox.alert("asdf");
                                            Ext.MessageBox.show
                                                    (
                                                        {
                                                            msg: '正在保存，请稍等...',
                                                            progressText: 'Saving...',
                                                            width: 300,
                                                            wait: true,
                                                            waitConfig: { interval: 200 },
                                                            icon: 'download',
                                                            animEl: 'saving'
                                                        }
                                                    );
                                                        setTimeout(function () { }, 1000);
                                                        
                                            InsertExtend_CollectSetInfoForm.form.submit({
                                                url: "/manager/Extend_CollectSetInfo/CollectContent/",
                                                method: "POST",
                                                success: function(form, action) {
                                                    Ext.MessageBox.hide();
                                                    //成功后
                                                    InsertExtend_CollectSetInfoForm.getForm().findField("reContent").setValue(action.result.message);
                                                },
                                                failure: function(form, action) {
                                                    Ext.MessageBox.alert("提示!", "新增失败!");
                                                }
                                            });
                                        }
                                    }

                                })
                        ]
                }, {
                    xtype: 'textareafield',
                    name: 'reContent',
                    fieldLabel: "采集内容",
                    width: 500,
                    height: 300,
                    flex: 1
                }

                         ]
}]

            }
        ]
        });


        var InsertExtend_CollectSetInfoWin = Ext.create('Ext.window.Window', {
            title: "新增采集规则设置",
            width: 830,
            //不可以随意改变大小
            //是否可以拖动
            //draggable:false,
            defaultType: "textfield",
            collapsible: true, //允许缩放条
            closeAction: 'hide',
            closable: true,
            //弹出模态窗体
            modal: 'true',
            buttonAlign: "center",
            bodyStyle: "padding:10px 0 0 15px",
            items: [InsertExtend_CollectSetInfoForm],

            buttons: [{
                text: "保存信息",
                minWidth: 70,
                handler: function() {
                    //alert(InsertExtend_CollectSetInfoForm.getForm().isValid())
                    if (InsertExtend_CollectSetInfoForm.getForm().isValid()) {
                        //弹出效果 Ext.MessageBox.alert("asdf");
                        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                        setTimeout(function() { }, 1000);
                        InsertExtend_CollectSetInfoForm.form.submit({
                            url: "/manager/Extend_CollectSetInfo/Insert/",
                            method: "POST",
                            success: function(form, action) {
                                //成功后
                                Ext.MessageBox.hide();
                                var flag = action.result.success;
                                if (flag == "true") {
                                    Extend_CollectSetInfoStore.loadPage(1);
                                    Ext.helper.msg("恭喜", "新增成功!");
                                    InsertExtend_CollectSetInfoWin.hide();
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("新增失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "新增失败!");
                                        InsertExtend_CollectSetInfoWin.hide();
                                    }

                                }
                            },
                            failure: function(form, action) {
                                Ext.MessageBox.alert("提示!", "新增失败!");
                            }
                        });
                    }
                }
            }, {
                text: "重置",
                minWidth: 70,
                qtip: "重置数据",
                handler: function() {
                    //加载表单数据
                    InsertExtend_CollectSetInfoForm.getForm().reset();
                }
            }, {
                text: "取 消",
                minWidth: 70,
                handler: function() {
                    InsertExtend_CollectSetInfoWin.hide();
                }
}]

            });

            InsertExtend_CollectSetInfoWin.show();
        }
